<?php
namespace Modules\Home\Services;

use Common\Models\UserWalletModel;

class UserWalletService {
  public function getOne($user_id) {
    $findFirstUserWallet = UserWalletModel::findFirst('user_id = ' . $user_id);
    if(!$findFirstUserWallet) {
      return $this -> create([
        'user_id' => $user_id,
        'goods' => 0,
        'declaration_coin' => 0,
        'tourism_integration' => 0,
        'coupon' => 0,
        'activation_code' => 0
      ]);
    }

    return ['code' => 0, 'user_wallet' => $findFirstUserWallet];
  }

  public function create($parameter) {

    $userWalletModel = new UserWalletModel($parameter);
    try {
      if(!$userWalletModel -> create()) {
        $messages = $userWalletModel -> getMessages();
        return ['code' => -1, 'message' => $messages[0] -> getMessage()];
      }
    } catch(\Exception $e) {
      return ['code' => -1, 'message' => $e -> getMessage()];
    }

    return ['code' => 0, 'user_wallet' => $userWalletModel];
  }
}
?>